Emacs Notes
Emacs Manual
48 Emacs Lisp Packages
Emacs package system allows you to downloads, install, uninstall and upgrade packages that add additional features.
M-x list-packages
brings a buffer named*Packages*
with a list of all packages.- The command
C-h P (describe-package)
prompts for the name of the package, and displays a help buffer describing the attributes of the package and the features that it implements.
The Package menu buffer
This buffer lists all the packages that Emacs know about, one on each line, with the following information:
- The package name.
- The package's version number.
- The package's status:
available
(can be downloaded from the package archive),installed
,built-in
(included in Emacs by default), ornew
(equivalent toavailable
, but this package becomes newly available on the package archive after your last invocation ofM-x list-packages
),held
(held inpackage-load-list
),disabled
,obsolete
. - A short description of the package.
The list-package
command access the network, to retrieve the list of all available packages from the package archive server. If the network is unavailable, it falls back on the most recent retrieved list.
Possible commands:
h (package-menu-quick-help)
Print a short message summarizing how to use the package menu buffer.?
or<RET>
(package-menu-describe-package
, display a help buffer for the package in the current line. Similar toC-h P
.i (package-menu-mark-install)
. Mark the package on the current line for installation, which will add anI
character to the start of the line if the package status isavailable
.d (package-menu-mark-delete)
. Mark the package on the current line for deletion, which will add aD
character to the start of the line if the package status isinstalled
.u (package-menu-mark-unmark)
. Clear any mark on the current line and move to next line.U (package-menu-mark-upgrades)
. PlaceI
flag for the newr version andD
flag for the old installed version.x (package-menu-execute)
. Download and install all the packages marked withI
and their dependencies, delete all teh packages marked withD
. This also removes the marks.r (package-menu-refresh)
. Refresh the package list by fetching the list of available packages from package archive again.f (package-menu-filter)
. Prompts a keyword, then shows only the packages that relate to that keyword. To retore the full package list, typeq
.
Package Installation
- A package's requirements list is shown in its help bufer.
package-archives
variable is a list of packages archives with each element of the form(id . location)
, whereid
is the name of a package archive andlocation
is the HTTP address or directory naem of the package archive.package-pinned-archive
variable to ensure that specified package is only ever downloaded from the specified archive.- Emacs will automatically load installed packages at startup, after processing the init file. As an exception, emacs don't do this if invoked with
-q
or--no-init-file
. To disable automatic package loading, usepackage-enable-at-startup
variable. - The reason why automatic package loading occurs after loading the init file is that user options only receive theri customized values after loading the init file, including user options affecting the package system. If you want to load packages expicitly in your init file (usually because some other code in your init file depends on a package), you can call
package-initialize
function, but changepackage-enable-at-startup
tonil
to avoid loading the packages again after processing the init file. - Use
package-load-list
to control which package to load.
Package files and Directory Layout
- Each package is either a single Elisp source file or a tar file containing mulple Emacs lisp source and other files.
- Use
package-install-file
to install a package from a file directly. - Contents of a packages are install in subdirectory of
package-user-dir
, which defaults to~/.emacs.d/elpa/
. The subdirectory is namedname-version
, wherename
is the package name andversion
is its version string. package-directory-list
variable defines system-wide packages Emacs look for. They have the same subdirectory layout.- Deleting a package will delete the corresponding package subdirectory as well, but will only apply for package installed in
package-user-dir
.
MISC
Variables
user-full-name
the full name of the user logged in.
user-mail-address
Full mailing address of the user.
mail-host-address
Name of the machine, for purposes of naming users. If non-nil, Emacs use this instead of system-name
when constructing email address
package-archives
package archive alist, with each element the form (ID . LOCATIN)
where ID
is the archive name, as a string, and LOCATION
is the location for archive. If LOCATION
starts with http:
, it's a HTTP URL, otherwise it should be an absolute directory name. Other types of URL are not supported yet.
Function
(getenv VARIABLE &optional FRAME)
Get the value of environment variable VARIABLE
, which is a string. Return nil
if VARIABLE
is undefined in the environmen. Otherwise, return a string.
(user-logini-name &optional UID)
Returnthe name under which the user logged in, as a string.
(system-name)
Return the host name of the machine you are running on, as a string.
(add-to-list LIST-VAR ELEMENT &optional APPEND COMPARE-FN)
Add ELEMENT
to the value of LIST-VAR
if it isn't there yet. The element is default added at the beginning of thel ist, unless APPEND
is non-nil.
Return the new value of LIST-VAR
.
(assoc-default KEY ALIST &optional TEST DEFAULT)
Find object KEY
in a pseudo-alist ALIST
. ALIST
is a llist of objects. Each element is compared with KEY
by callling TEST
.
Return the element's cdr if matches. Otherwiser, return nil
.
(package-installed-p PACKAGE &optional MIN-VERSION)
Return ture if PACKAGE
, of MIN-VERSION
or newer, is installed. MIN-VERSION
should be a version list.
(package-install PKG)
Install the package PKG
, which can be a package-desc or package name of one the vavailable packages in package-archies
. Inactively, prompt for its name.
(buffer-file-name &optional BUFFER)
Return name of ile BUFFER
is visiting, or nil
if none. No argument or nil
as argument means use the current buffer.
(kill-new STRING &optional REPLACE)
Make STRING
the latest kill in the kill ring.
Package
auto-compile
- Description
This package provides two minor modes which automatically recompile Emacs Lisp source files, to guarantee that Emacs never load outdated byte code files.
auto-compile-on-save-mode
re-compiles source files when they are being saved.auto-compile-on-load-mode
re-compiles source files when they are being loaded (by advisingload
andrequire
)
These two modes only recomple the source file when the respective byte code file already exist but is outdated.
Starting with Emacs 24.4, setting
load-prefer-newer
tot
to prevent outdated byte code files being loaded. However, this doesn't re-compile the source file.